package com.fengwei.security;

import com.fengwei.util.GsonUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.SimpleUrlLogoutSuccessHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class AjaxLogoutSuccessHandler extends SimpleUrlLogoutSuccessHandler {

    private final Logger logger = LoggerFactory.getLogger(AjaxLogoutSuccessHandler.class);

    @Override
    public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse httpServletResponse, Authentication authentication)
            throws IOException, ServletException {
        Map map = new HashMap();
        map.put("result", "0000");
        map.put("data", new HashMap<>());

        httpServletResponse.setContentType("text/json;charset=utf-8");
        httpServletResponse.getWriter().write(GsonUtil.toJson(map, false));
    }
}
